/*
 * x86_64/io.hh - Port I/O functions.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#ifndef HEADER_X86_64_IO_HH
#define HEADER_X86_64_IO_HH

START_NAMESPACE (x86_64)

INLINE
static u8_t
in8 (u16_t port)
{
  u8_t result;
  asm volatile (
    "inb %1, %0\n"
    : "=a"(result)
    : "dN"(port)
  );
  return result;
}

INLINE
static void
out8 (u16_t port, u8_t value)
{
  asm volatile (
    "outb %1, %0\n"
    :
    : "dN"(port), "a"(value)
  );
}

INLINE
static u16_t
in16 (u16_t port)
{
  u16_t result;
  asm volatile (
    "inw %1, %0\n"
    : "=a"(result)
    : "dN"(port)
  );
  return result;
}

INLINE
static void
out16 (u16_t port, u16_t value)
{
  asm volatile (
    "outw %1, %0\n"
    :
    : "dN"(port), "a"(value)
  );
}

INLINE
static u32_t
in32 (u16_t port)
{
  u32_t result;
  asm volatile (
    "inl %1, %0\n"
    : "=a"(result)
    : "dN"(port)
  );
  return result;
}

INLINE
static void
out32 (u16_t port, u32_t value)
{
  asm volatile (
    "outb %1, %0\n"
    :
    : "dN"(port), "a"(value)
  );
}

END_NAMESPACE

#endif /* HEADER_X86_64_IO_HH */

